package thread;

public class demo2 {
    private static Object locker1 = new Object();
    private static Object locker2 = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(() ->{
            synchronized (locker1){
                //此时的休眠十分重要，确保t1和t2都拿到一把锁之后再进行后续操作
                try{
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }

                synchronized (locker2){

                }
            }

        });
        Thread t2 = new Thread(() ->{
            synchronized (locker2){
                synchronized (locker1){

                }
            }

        });
        t1.start();
        t2.start();
    }

}
